﻿
using StrokeCenterSystem.Bll;
using StrokeCenterSystem.Core;
using StrokeCenterSystem.ThreeCenterManage;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using StrokeCenterSystem.Areas.StrokeCenter.Models;

namespace StrokeCenterSystem.Code.Bll
{
    public class PathwayManager : BaseManager
    {
        /// <summary>
        /// 获取诊疗路径列表
        /// </summary>
        /// <param name="pathName"></param>
        /// <returns></returns>
        public static OperateResult GetDiagnosticPath(int pageIndex,int pageSize, string pathName)
        {
            OperateResult resultInfo = new OperateResult();
            try
            {
                ThreeCenterManageSoapClient service = new ThreeCenterManageSoapClient();
                ResultHelperOfString result = service.GetDiagnosticPath(pathName, pageIndex, pageSize);
                if (result.S)
                {
                    resultInfo.Body = result.D;
                }
                else
                {
                    resultInfo.Body = result.M;
                }
            }
            catch (Exception ex)
            {
                resultInfo.Result = -1;
                resultInfo.Body = ex.Message;
            }
            return resultInfo;
        }



        /// <summary>
        /// 获取诊疗路径名称列表
        /// ID Name 
        /// </summary>
        /// <returns></returns>
        public static OperateResult GetPathNameList()
        {
            OperateResult resultInfo = new OperateResult();
            try
            {
                ThreeCenterManageSoapClient service = new ThreeCenterManageSoapClient();
                ResultHelperOfString result = service.GetPathNameList();
                if (result.S)
                {
                    resultInfo.Body = result.D;
                }
                else
                {
                    resultInfo.Body = result.M;
                }
            }
            catch (Exception ex)
            {
                resultInfo.Result = -1;
                resultInfo.Body = ex.Message;
            }            
            return resultInfo;
        }

        /// <summary>
        /// 新增或编辑诊疗路径 依据ID
        /// </summary>
        /// <param name="pathJson"></param>
        /// <returns></returns>
        public static OperateResult SavePathName(string pathJson) 
        {
            OperateResult resultInfo = new OperateResult();
            try
            {
                ThreeCenterManageSoapClient service = new ThreeCenterManageSoapClient();               
                ResultHelperOfBoolean result = service.SetDiagnosticPath(pathJson);
                if (result.S)
                {
                    resultInfo.Body = result.M;
                }
                else
                {
                    resultInfo.Body = result.M;
                }
            }
            catch (Exception ex)
            {
                resultInfo.Result = -1;
                resultInfo.Body = ex.Message;
            }

            return resultInfo;
        }

        /// <summary>
        /// 返回诊疗路径对象
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public static OperateResult GetDiagnosticPathById(int Id) 
        {
            OperateResult resultInfo = new OperateResult();
            try
            {
                ThreeCenterManageSoapClient service = new ThreeCenterManageSoapClient();
                ResultHelperOfString result = service.GetDiagnosticPathById(Id);
                if (result.S)
                {
                    resultInfo.Body = result.D;
                }
                else
                {
                    resultInfo.Body = result.M;
                }
            }
            catch (Exception ex)
            {
                resultInfo.Result = -1;
                resultInfo.Body = ex.Message;
            }

            return resultInfo;
        }

        /// <summary>
        /// 根据诊疗路径ID获取模板或内容
        /// </summary>
        /// <param name="pathId"></param>
        /// <returns></returns>
        public static OperateResult GetDiagnosticPathTemp(int pathId, string patientId) 
        {
            OperateResult resultInfo = new OperateResult();
            try
            {
                ThreeCenterManageSoapClient service = new ThreeCenterManageSoapClient();
                ResultHelperOfString result = service.GetDiagnosticPathTemp(pathId, patientId);
                if (result.S)
                {
                    resultInfo.Body = result.D;
                }
                else
                {
                    resultInfo.Body = result.M;
                }
            }
            catch (Exception ex)
            {
                resultInfo.Result = -1;
                resultInfo.Body = ex.Message;
            }
            return resultInfo;
        }

        /// <summary>
        /// 保存诊疗路径模板
        /// </summary>
        /// <param name="contentJson"></param>
        /// <returns></returns>
        public static OperateResult SetDiagnosticPathTemp(string contentJson) 
        {
            OperateResult resultInfo = new OperateResult();
            try
            {
                ThreeCenterManageSoapClient service = new ThreeCenterManageSoapClient();
                ResultHelperOfBoolean result = service.SetDiagnosticPathTemp(contentJson);
                if (result.S)
                {
                    resultInfo.Body = result.D;
                }
                else
                {
                    resultInfo.Body = result.M;
                }
            }
            catch (Exception ex)
            {
                resultInfo.Result = -1;
                resultInfo.Body = ex.Message;
            }
            return resultInfo;
        }



        /// <summary>
        /// 获取质控列表（或者单个）
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static OperateResult GetQualityPointList(int id = -1)
        {
            OperateResult resultInfo = new OperateResult();
            try
            {
                ThreeCenterManageSoapClient service = new ThreeCenterManageSoapClient();
                ResultHelperOfString result = service.Get_QualityPointSet(id);
                if (result.S)
                {
                    resultInfo.Body = result.D;
                }
                else
                {
                    resultInfo.Result = 0;
                    resultInfo.Body = result.M;
                }
            }
            catch (Exception ex)
            {
                resultInfo.Result = -1;
                resultInfo.Body = ex.Message;
            }
            return resultInfo;
        }

        /// <summary>
        /// 保存质控项
        /// </summary>
        /// <param name="qp"></param>
        /// <returns></returns>
        public static OperateResult SaveQualityPoint(QualityPointSet qp)
        {
            OperateResult resultInfo = new OperateResult();
            try
            {
                ThreeCenterManageSoapClient service = new ThreeCenterManageSoapClient();
                ResultHelperOfBoolean result = service.Set_QualityPointSet(qp);
                if (result.S)
                {
                    resultInfo.Body = result.D;
                }
                else
                {
                    resultInfo.Result = 0;
                    resultInfo.Body = result.M;
                }
            }
            catch (Exception ex)
            {
                resultInfo.Result = -1;
                resultInfo.Body = ex.Message;
            }
            return resultInfo;
        }


        /// <summary>
        /// 更新质控项状态（删除）
        /// </summary>
        /// <param name="id"></param>
        /// <param name="status"></param>
        /// <returns></returns>
        public static OperateResult ChangeStatus(int id, int status)
        {
            OperateResult resultInfo = new OperateResult();
            try
            {
                ThreeCenterManageSoapClient service = new ThreeCenterManageSoapClient();
                ResultHelperOfBoolean result = service.Del_QualityPointSet(id);
                if (result.S)
                {
                    resultInfo.Body = result.D;
                }
                else
                {
                    resultInfo.Result = 0;
                    resultInfo.Body = result.M;
                }
            }
            catch (Exception ex)
            {
                resultInfo.Result = -1;
                resultInfo.Body = ex.Message;
            }
            return resultInfo;
        }


        /// <summary>
        /// 获取已开启的质控项列表
        /// ID Name 
        /// </summary>
        /// <returns></returns>
        public static OperateResult GetOpenQuanlityPointList(string PatientID)
        {
            OperateResult resultInfo = new OperateResult();
            try
            {
                ThreeCenterManageSoapClient service = new ThreeCenterManageSoapClient();
                ResultHelperOfDataCompleteTimeLine result = service.GetTimeline(PatientID);
                if (result.S)
                {
                    resultInfo.Body = result.D;
                }
                else
                {
                    resultInfo.Body = result.M;
                }
            }
            catch (Exception ex)
            {
                resultInfo.Result = -1;
                resultInfo.Body = ex.Message;
            }
            return resultInfo;
        }
        /// <summary>
        /// 获取子集字段列表
        /// </summary>
        /// <returns></returns>
        public static OperateResult GetTableColumnList()
        {
            OperateResult resultInfo = new OperateResult();
            try
            {
                ThreeCenterManageSoapClient service = new ThreeCenterManageSoapClient();
                ResultHelperOfString result = service.GetTableColumn();
                if (result.S)
                {
                    resultInfo.Body = result.D;
                }
                else
                {
                    resultInfo.Result = 0;
                    resultInfo.Body = result.M;
                }
            }
            catch (Exception ex)
            {
                resultInfo.Result = -1;
                resultInfo.Body = ex.Message;
            }
            return resultInfo;
        }


    }
}